package com.xiaofeng.student.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.xiaofeng.student.entity.Area;
import com.xiaofeng.student.entity.Student;
import com.xiaofeng.student.entity.Subject;

/**
 * 
 * @author zhuzg
 *
 */
public interface StudentMapper {
	
	/**
	 * 根据学生姓名查询学生列表
	 * @param name
	 * @return
	 */
	List<Student> list(String name);

	/**
	 * 
	 * @param parentId
	 * @return
	 */
	@Select("SELECT id,name FROM stu_area WHERE parentId=#{value}")
	List<Area> listAreasByParentId(int parentId);

	/**
	 * 
	 * @return
	 */
	@Select("SELECT id,name FROM stu_subject ")
	List<Subject> listAllSubjects();

	
	void add(Student stu);

	/**
	 * 
	 * @param stuId 学生的主键
	 * @param subId  科目的主键
	 */
	@Insert("INSERT INTO stu_student_subject(student_id,subject_id) "
			+ "VALUES(#{stuId},#{subId}) ")
	void addStuSub(@Param("stuId") Integer stuId,@Param("subId") int subId);

	
	Student getById(int id);

	/**
	 * 修改学生表
	 * @param stu
	 * name	 */
	@Update("UPDATE stu_students SET name=#{name} ,enter_date=#{enterDate} ,province_id=#{provinceId}"
			+ ", city_id=#{cityId} , county_id=#{countyId} WHERE id=#{id}")
	void update(Student stu);

	/**
	 * 删除学生的科目
	 * @param id
	 */
	@Delete("DELETE FROM stu_student_subject WHERE student_id=#{value}")
	void delSubjectByStuId(Integer id);

	void delBathcSubjectByStuIds(int[] ids);

	void delBatch(int[] ids);
	
	List<Student> listBySub(@Param("name") String name,@Param("selSubId") int[] selSubId);
	
}
